home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / zapem-0.000 / zapem-0 / zapem / animation.cc < prev    next >
C/C++ Source or Header  |  1995-05-06  |  2KB  |  123 lines

  1. /*    Copyright Alex Hornby 1994/1995. All rights reserved.
  2.      See file README for details
  3. */
  4.  
  5. #include "animation.h"
  6. extern "C" {
  7. #include <assert.h>
  8. }
  9.  
  10. slotElt Animation :: sprbank[MAXFRAME];
  11.  
  12. struct animElt animElt(int s, int d)
  13. {
  14.     struct animElt r;
  15.     r.slot=s;
  16.     r.duration=d;
  17.     return r;
  18. }
  19.  
  20. animList operator+( struct animElt a, struct animElt b)
  21. {
  22.     animList l;
  23.     l.append(a); l.append(b);
  24.     return l;
  25. }
  26.  
  27. animList operator+(animList l, struct animElt a)
  28. {
  29.     l.append(a);
  30.     return l;
  31. }
  32.  
  33. Animation::Animation()
  34. {
  35.     animflag=false;
  36. }
  37.  
  38. Animation::Animation( const Animation& a)
  39. {
  40.     setSlot(a.curslot);
  41.     anim=a.anim;
  42.     curframe=0;
  43.     setAnim(a.getAnim());
  44. }
  45.  
  46. Animation&
  47. Animation::operator=( const Animation& a)
  48. {
  49.     if( &a == this)
  50.         return *this;
  51.  
  52.     setSlot(a.curslot);
  53.     anim=a.anim;
  54.     curframe=0;
  55.     setAnim(a.getAnim());
  56.     return *this;
  57. }
  58.  
  59. void
  60. Animation :: setAnim( bool v )
  61. {
  62.     if( v==true)
  63.     {
  64.         curframe=anim.first();
  65.         animflag=true;
  66.         framecounter=0;
  67.     }
  68.     else
  69.     {
  70.         curframe=0;
  71.         animflag=false;
  72.     }
  73. }
  74.  
  75. void
  76. Animation :: loadFilm( animList a)
  77. {
  78.     anim=a;
  79.     curframe=anim.first();
  80. }
  81.  
  82. void
  83. Animation :: doAnim( void )
  84. {
  85.  
  86.     assert(curframe!=0);
  87.     if(framecounter< anim(curframe).duration)
  88.     {
  89.         setSlot(anim(curframe).slot);
  90.         framecounter++;
  91.     }
  92.     else
  93.     {
  94.         framecounter=0;
  95.         anim.next(curframe);
  96.         if(curframe==0)
  97.             setAnim(false);
  98.         else 
  99.         {
  100.             switch( anim(curframe).slot)
  101.             {
  102.             case LOOPANIM:
  103.                 setAnim(true);
  104.                 break;
  105.             case VANISHANIM:
  106.                 setVisible(false);
  107.                 setAnim(false);
  108.                 break;
  109.             default:
  110.                 setSlot(anim(curframe).slot);
  111.             }
  112.         }
  113.     }
  114. }
  115.  
  116. void 
  117. Animation :: setSlot(int slot)
  118. {
  119.     assert(slot<MAXFRAME);
  120.     assert(slot>=0);
  121.     curslot=slot;
  122. }
  123.